package com.galaxy.order.api;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.galaxy.common.core.domain.R;
import com.galaxy.common.core.validate.AddGroup;
import com.galaxy.common.core.validate.EditGroup;
import com.galaxy.common.log.annotation.Log;
import com.galaxy.common.log.enums.BusinessType;
import com.galaxy.common.mybatis.core.page.PageQuery;
import com.galaxy.common.mybatis.core.page.TableDataInfo;
import com.galaxy.order.domain.OrderCoupon;
import com.galaxy.order.domain.bo.OrderCouponBo;
import com.galaxy.order.domain.vo.OrderCouponVo;
import com.galaxy.order.service.OrderCouponService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 订单优惠券信息Controller
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/api/orderCoupon")
public class OrderCouponApiController {

    @Autowired
    private OrderCouponService orderCouponService;

    /**
     * 查询订单优惠券信息列表
     */
    @GetMapping("/list")
    public TableDataInfo<OrderCouponVo> list(OrderCouponBo bo, PageQuery pageQuery) {
        return orderCouponService.queryPageList(bo, pageQuery);
    }

    /**
     * 获取订单优惠券详细信息
     */
    @GetMapping("/{id}")
    public R<OrderCoupon> getInfo(@PathVariable("id") Long id) {
        return R.ok(orderCouponService.queryById(id));
    }

    /**
     * 新增订单优惠券信息
     */
//    @Log(title = "订单优惠券信息", businessType = BusinessType.INSERT)
    @PostMapping
    public R<Boolean> add(@Validated(AddGroup.class) @RequestBody OrderCouponBo bo) {
        return R.ok(orderCouponService.insertByBo(bo));
    }

    /**
     * 修改订单优惠券信息
     */
//    @Log(title = "订单优惠券信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public R<Boolean> edit(@Validated(EditGroup.class) @RequestBody OrderCouponBo bo) {
        return R.ok(orderCouponService.updateByBo(bo));
    }

    /**
     * 删除订单优惠券信息
     */
//    @Log(title = "订单优惠券信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Boolean> remove(@PathVariable Long[] ids) {
        return R.ok(orderCouponService.deleteWithValidByIds(List.of(ids), true));
    }

    /**
     * 查询订单优惠券信息列表（不分页）
     */
    @GetMapping("/listOrderCoupon")
    public R<List<OrderCouponVo>> list(OrderCouponBo bo) {
        return R.ok(orderCouponService.queryList(bo));
    }
}
